package com.leetcode.dataStruct;

import com.leetcode.math.ListNode;

public class ReverseBetween {
    public static void main(String[] args) {

    }

    public ListNode reverseBetween(ListNode head, int left, int right) {
        ListNode dump = new ListNode(0, head);
        ListNode pre = dump;
        for (int i = 1; i < left; i++) {
            pre = pre.next;
        }
        ListNode cur = pre.next;
        for (int i = 0; i < right - left; i++) {
            ListNode next = cur.next;
            cur.next = next.next;
            next.next = pre.next;
            pre.next = next;
        }
        return dump.next;
    }
}
